package huawei.dpoint;

import ListNode.ListNode;

public class JOffer52 {
    public static void main(String[] args){
        ListNode a=ListNode.createListNode(4,1);
        ListNode b=ListNode.createListNode(5,0,1);
        ListNode c= ListNode.createListNode(8,4,5);
        ListNode tmp = a;
        while (tmp.next!=null){
            tmp=tmp.next;
        }
        tmp.next=c;
        tmp = b;
        while (tmp.next!=null){
            tmp=tmp.next;
        }
        tmp.next=c;
        System.out.println(getIntersectionNode(a,b));
    }
    public static ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode tmpA= headA;
        ListNode tmpB= headB;
        while (tmpA!=tmpB){
           if(tmpA==null){
               tmpA=headB;
           }else {
               tmpA=tmpA.next;
           }
           if(tmpB==null){
               tmpB=headA;
           }else {
               tmpB=tmpB.next;
           }
        }
        return tmpA;
    }
}
